<h1><?php echo $__title ?></h1>


<?php if ( $__session->isAuthenticated() ): ?>
<a class="float-right submit" style="margin-bottom:10px" href="<?php link_to('forum', 'discussion', 'create-message', array($discussion->getId(), slugify($discussion->getTitle()))) ?>">Répondre à la discussion</a>
<hr />
<?php endif ?>

<?php foreach ($messages AS $key => $message): ?>
    <a name="message<?php echo $message->getId() ?>"></a>
    <table class="list">
        <thead>
            <tr>
                <th colspan="2" class="right"><?php date_to($message->getCreatedAt(),true) ?></th>
            </tr>
        </thead>
        <tbody>
            <?php if ($key%2==0): ?>
            <tr>
                <td style="width:150px" class="center"><a href="<?php link_to('user', 'profil', null, array($message->getUser()->getId(), slugify($message->getUser()->getName()))) ?>"><?php if ( $message->getUser()->getAvatar() != '' ): ?><img src="<?php echo $message->getUser()->getAvatar() ?>" alt="Avatar de <?php echo $message->getUser()->getName() ?>" /><?php else: ?>Avatar<?php endif ?><br /><?php echo $message->getUser()->getLink() ?></td>
                <td>
                    <p><?php echo $message->getContent() ?></p>
                    <?php if ( $__session->isAuthenticated() ): ?>
                     <div class="right" style="margin-top:10px">
                        <?php if ( $__session->hasCredential('forums_edit') OR ($message->getUser()->getId() == $__session->getUser()->getId()) ): ?>
                         <a class="edit" title="Modifier ce message" href="<?php link_to('forum', 'discussion', 'edit-message', array($message->getId(), slugify(resume($message->getContent(),20)))) ?>"><span class="no-display">Modifier ce message</span></a>
                        <?php endif ?>
                         <?php if ( $__session->hasCredential('forums_delete') OR ( ($message->getUser()->getId() == $__session->getUser()->getId()) AND ($message->getId() == $discussion->getMessages()->last()->getId())) ): ?>
                         <a class="delete" title="Supprimer ce message" href="<?php link_to('forum', 'discussion', 'delete-message', array($message->getId(), slugify(resume($message->getContent(),20)))) ?>"><span class="no-display">Modifier ce message</span></a>
                        <?php endif ?>
                     </div>
                    <?php endif ?>
                </td>
            </tr>
            <?php else: ?>
            <tr>
                <td>
                    <p><?php echo $message->getContent() ?></p>
                    <?php if ( $__session->isAuthenticated() ): ?>
                     <div class="left" style="margin-top:10px">
                        <?php if ( $__session->hasCredential('forums_edit') OR ($message->getUser()->getId() == $__session->getUser()->getId()) ): ?>
                         <a class="edit" title="Modifier ce message" href="<?php link_to('forum', 'discussion', 'edit-message', array($message->getId(), slugify(resume($message->getContent(),20)))) ?>"><span class="no-display">Modifier ce message</span></a>
                        <?php endif ?>
                         <?php if ( $__session->hasCredential('forums_delete') OR ( ($message->getUser()->getId() == $__session->getUser()->getId()) AND ($message->getId() == $discussion->getMessages()->last()->getId())) ): ?>
                         <a class="delete" title="Supprimer ce message" href="<?php link_to('forum', 'discussion', 'delete-message', array($message->getId(), slugify(resume($message->getContent(),20)))) ?>"><span class="no-display">Modifier ce message</span></a>
                        <?php endif ?>
                     </div>
                    <?php endif ?>
                </td>
                <td style="width:150px" class="center"><?php if ( $message->getUser()->getAvatar() != '' ): ?><img src="<?php echo $message->getUser()->getAvatar() ?>" alt="Avatar de <?php echo $message->getUser()->getName() ?>" /><?php else: ?>Avatar<?php endif ?><br /><?php echo $message->getUser()->getLink() ?></td>
            </tr>
            <?php endif ?>
        </tbody>
    </table>
<?php endforeach ?>


<?php if ( $__session->isAuthenticated() ): ?>
<div class="right" style="margin-top:30px">
    <a class="submit" href="<?php link_to('forum', 'discussion', 'create-message', array($discussion->getId(), slugify($discussion->getTitle()))) ?>">Répondre à la discussion</a>
</div>
<hr />
<?php endif ?>

<?php $pagination->render() ?>